package com.ruoyi.door.controller.admin.orderdetail.vo;

import cn.hutool.core.date.DateUtil;
import com.easy.query.core.annotation.Column;
import com.easy.query.core.annotation.EntityProxy;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.door.domain.DoorOrderDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@EntityProxy
@Data
public class DoorOrderDetailRespVO extends DoorOrderDetail {
    @Column(exist = false)
    private String landlordName;

    @Column(exist = false)
    private String landlordPhone;
    /**
     * 国家
     */
    @Excel(name = "国家")
    @ApiModelProperty("国家")
    private String countryName;

    /**
     * 省
     */
    @Excel(name = "省")
    @ApiModelProperty("省")
    private String provinceName;

    /**
     * 市
     */
    @Excel(name = "市")
    @ApiModelProperty("市")
    private String cityName;

    /**
     * 区
     */
    @Excel(name = "区")
    @ApiModelProperty("区")
    private String districtName;

    /**
     * 街道
     */
    @Excel(name = "街道")
    @ApiModelProperty("街道")
    private String streetName;

    /**
     * 村
     */
    @Excel(name = "村")
    @ApiModelProperty("村")
    private String villageName;

    /**
     * 详细地址
     */
    @Excel(name = "详细地址")
    @ApiModelProperty("详细地址")
    private String address;

    /**
     * 门牌
     */
    @Excel(name = "门牌")
    @ApiModelProperty("门牌")
    private String door;



    /**
     * 月租
     */
    @Excel(name = "月租")
    @ApiModelProperty("月租")
    private BigDecimal monthPrice;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "缴费开始日期", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty("缴费开始日期")
    private Date startDate;


    /**
     * 截止日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "缴费截止日期", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty("缴费截止日期")
    private Date endDate;

    /**
     * 国家
     */
    @Excel(name = "国家")
    @ApiModelProperty("国家")
    private Long country;

    /**
     * 省
     */
    @Excel(name = "省")
    @ApiModelProperty("省")
    private Long province;

    /**
     * 市
     */
    @Excel(name = "市")
    @ApiModelProperty("市")
    private Long city;

    /**
     * 区
     */
    @Excel(name = "区")
    @ApiModelProperty("区")
    private Long district;

    /**
     * 街道
     */
    @Excel(name = "街道")
    @ApiModelProperty("街道")
    private Long street;

    /**
     * 村
     */
    @Excel(name = "村")
    @ApiModelProperty("村")
    private Long village;



    /**
     * 房东---sysUser.id
     */
    @Excel(name = "房东")
    @ApiModelProperty("房东")
    private Long landlordId;


    private Long deptId;

    private Long type;

    @JsonProperty("balance")
    private BigDecimal getBalance() {
        if (endDate == null || monthPrice == null) {
            return BigDecimal.ZERO;
        }

        // 获取当前日期
        Date now = new Date();

        // 计算年月差
        int yearDiff = DateUtil.year(endDate) - DateUtil.year(now);
        int monthDiff = DateUtil.month(endDate) - DateUtil.month(now);

        // 计算总月数差
        int totalMonthDiff = yearDiff * 12 + monthDiff;

        // 处理日期部分：如果当前日期的日部分大于截止日期的日部分，则多算一个月
        int endDay = DateUtil.dayOfMonth(endDate);
        int nowDay = DateUtil.dayOfMonth(now);

        if (nowDay > endDay) {
            totalMonthDiff--;
        }

        // 计算余额 = 月数差 * 月租
        return monthPrice.multiply(BigDecimal.valueOf(totalMonthDiff));
    }
}
